package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.enjoyor.health.HGPT.core.entity.News;
import com.enjoyor.health.HGPT.core.entity.SelftestContent;
import com.enjoyor.health.HGPT.core.mapper.SelftestContentMapper;
import com.enjoyor.health.HGPT.core.service.ISelftestContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class SelftestContentServiceImpl extends ServiceImpl<SelftestContentMapper, SelftestContent> implements ISelftestContentService {


    @Override
    public List<SelftestContent> getSelftestContentBySelftestId(String selftestId) {
        QueryWrapper<SelftestContent> queryWrapper = Wrappers.query();
        queryWrapper.eq("id", selftestId);
        queryWrapper.isNotNull("base_info");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<SelftestContent> getSelftestContentByScore(int score, String selftestId) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("score", score);
        map.put("selftest_id", selftestId);
        return baseMapper.getSelftestContentByScore(map);
    }

    @Override
    public List<SelftestContent> getSelftestContentList() {
        QueryWrapper<SelftestContent> queryWrapper = Wrappers.query();
        queryWrapper.isNotNull("base_info");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Page<SelftestContent> getSelfTestContePage(String title, String state, int page, int size) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("state", state);
        map.put("title", title);
        Page<SelftestContent> p = new Page<>(page, size);
//        p.addOrder(OrderItem.desc("up"), OrderItem.desc("edit_time"));
        return baseMapper.getSelfTestPage(p, map);
    }

    @Override
    public List<SelftestContent> getSelfTestContentById(String id) {
        QueryWrapper<SelftestContent> queryWrapper = Wrappers.query();
        queryWrapper.eq("id", id)
                .orderByAsc("low_score");
        return baseMapper.selectList(queryWrapper);
    }
}
